package geez.widget;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Widget;
import static geez.widget.Geez.withNameAndId;
import static geez.widget.Geez.withStyle;

public class GAnchor extends Widget {

    public GAnchor() {
        setElement(DOM.createAnchor());
    }

    public GAnchor append(Widget widget) {
        getElement().appendChild(widget.getElement());
        return this;
    }

    public GAnchor setUrl(String url) {
        DOM.setElementAttribute(getElement(), "href", url);
        return this;
    }

    public String getUrl() {
        return DOM.getElementAttribute(getElement(), "href");
    }

    public GAnchor openInNewWindow() {
        return setTargetWindow("_blank");
    }


    public GAnchor openInParent() {
        return setTargetWindow("_parent");
    }

    public GAnchor openInSelf() {
        return setTargetWindow("_self");
    }

    public GAnchor openInTop() {
        return setTargetWindow("_top");
    }

    public GAnchor setTargetWindow(String target) {
        DOM.setElementAttribute(getElement(), "target", target);
        return this;
    }

    public GAnchor css(String cssClass, String... optionalClasses) {
        return withStyle(this, cssClass, optionalClasses);
    }

    public GAnchor id(String id) {
        return withNameAndId(this, id);
    }

    public GAnchor title(String title) {
        DOM.setElementAttribute(getElement(), "title", title);
        return this;
    }
}
